import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:test1/xykk/app_page_view.dart';
import '../../app_meta.dart';
import '../model/UserModel.dart';
import 'login_logic.dart';

@AppPageAttributes("登录页面")
class LoginPage extends GetPageView<LoginLogic> {
   LoginPage({super.key});

  @override
  Widget buildLayout(BuildContext context) {
    var state = controller.state;
    var logic = controller;
    print('JtTag:LoginPage:执行build');
    return Scaffold(
        appBar: AppBar(title: const Text('LoginPage')),
        body: Column(children: [
          Center(
            child: SingleChildScrollView(
              padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 40),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  // logo
                  const FlutterLogo(size: 100),
                  const SizedBox(height: 40),
                  TextButton(
                      onPressed: () {
                        state?.userModel.value.name += '1';
                      },
                      child: Text('${state?.userModel.toJson()}')
                  ),
                  ObxValue<Rx<UserModel>>((data) {
                    return TextButton(
                        onPressed: () {

                        },
                        child: Text('${data.value.toJson()}')
                    );
                  }, state!.userModel2),
                  // 输入框卡片
                  Container(
                    padding: const EdgeInsets.all(24),
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(16),
                      boxShadow: [
                        BoxShadow(
                          color: Colors.black.withOpacity(0.05),
                          blurRadius: 10,
                          offset: const Offset(0, 4),
                        ),
                      ],
                    ),
                    child: Column(
                      children: [
                        // 账号输入框
                        TextField(
                          controller: state?.accountController,
                          decoration: const InputDecoration(
                            labelText: '账号',
                            prefixIcon: Icon(Icons.person_outline),
                            border: OutlineInputBorder(),
                          ),
                        ),
                        const SizedBox(height: 20),
                        //
                        // // 密码输入框
                        TextField(
                          controller: state?.passwordController,
                          obscureText: true,
                          decoration: const InputDecoration(
                            labelText: '密码',
                            prefixIcon: Icon(Icons.lock_outline),
                            border: OutlineInputBorder(),
                          ),
                        ),
                        const SizedBox(height: 30),

                        // 登录按钮
                        SizedBox(
                          width: double.infinity,
                          height: 48,
                          child: ElevatedButton(
                            style: ElevatedButton.styleFrom(
                              backgroundColor: Colors.blueAccent,
                              shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(12),
                              ),
                            ),
                            // onPressed: _onLogin,
                            onPressed: () {
                              logic.login();
                            },
                            child: const Text(
                              '登录',
                              style: TextStyle(
                                fontSize: 16,
                                color: Colors.white,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                          ),
                        ),
                        const SizedBox(height: 30),
                        // // 查看数据
                        SizedBox(
                          width: double.infinity,
                          height: 48,
                          child: ElevatedButton(
                            style: ElevatedButton.styleFrom(
                              backgroundColor: Colors.blueAccent,
                              shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(12),
                              ),
                            ),
                            // onPressed: _onLogin,
                            onPressed: () {
                              logic.check();
                            },
                            child: const Text(
                              '查看',
                              style: TextStyle(
                                fontSize: 16,
                                color: Colors.white,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ),
          Image.asset('assets/rectangle_slices.png',
              color: Colors.red, height: 100, width: 100),

        ]));

  }
}

